package edu.sysu.demo.petstore.dog.web.rest;

import static org.assertj.core.api.Assertions.assertThat;

import edu.sysu.demo.petstore.dog.RandomStringBuilder;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

public class RegisterControllerIT {


  private final TestRestTemplate restTemplate = new TestRestTemplate();

  private RandomStringBuilder rand;

  @Before
  public void setUp() {
    rand = RandomStringBuilder.newBuilder()
        .useDigit()
        .useUpperCase()
        .useLowerCase()
        .useSymbol();
  }

  @Test
  public void registerSuccess() {
    final String username = rand.build(22);
    RegisterForm registerForm = new RegisterForm(username, rand.build(32));

    ResponseEntity<RegisterResult> response = restTemplate.postForEntity(
        Location.REGISTER.getUrl(),
        registerForm,
        RegisterResult.class);

    assertThat(response).isNotNull();
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(response.getBody()).isNotNull();
    assertThat(response.getBody().getUsername()).isEqualTo(username);
  }
}